/**
 * Created by Administrator on 2018/10/28.
 */
$(function () {
    var $oldPassword = $('#changePassword-lodPassword');
    var $newPassword = $('#changePassword-password');
    var $passwordAgain = $('#changePassword-passwordAgain');
    var $changePasswordSub = $('#changePassword-sub');


    $changePasswordSub.on('click', function () {
        var oldPassword = $oldPassword.val();
        var newPassword = $newPassword.val();
        var passwordAgain = $passwordAgain.val();
        if (!oldPassword) {
            _alert('请输入旧密码');
            return;
        }
        if (!newPassword) {
            _alert('请输入新密码');
            return;
        }
        if (!passwordAgain) {
            _alert('请再次输入新密码');
            return;
        }
        if (newPassword != passwordAgain) {
            _alert('两次输入新密码不一致');
            return;
        }
        ajax({
            url: 'app/user/updatePwd',
            data: {
                oldPsd: oldPassword,
                password: newPassword
            },
            success: function (d) {
                _alert('修改密码成功');
                // removeUserInfo();
                setTimeout(function () {
                    window.location.href = 'home.html';
                }, 2000);
            },
            fail: function () {
                _alert('修改密码失败');
            }
        })
    });
});